package fina2.dcs.mail.dbo.domain;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import fina2.dcs.mail.util.MailUtil;

@SuppressWarnings("serial")
@Entity
@Table(name = "IN_MAIL_REPLAY")
public class MailReply implements Serializable {

	@Id
	@Column(name = "MAIL_ID")
	@GeneratedValue
	private long id;

	@Column(name = "MAIL_FROM", nullable = false)
	private String from;

	@Column(name = "MAIL_TO", nullable = false, length = 512)
	private String to;

	@Lob
	@Column(name = "MAIL_CC")
	private String cc;

	@Lob
	@Column(name = "MAIL_BCC")
	private String bcc;

	@Column(name = "MAIL_SENDER", nullable = false)
	private String sender;

	@Lob
	@Column(name = "MAIL_CONTENT")
	private String content;

	@Column(name = "MAIL_DATE", nullable = false)
	@Temporal(TemporalType.TIMESTAMP)
	private Date date;

	@Column(name = "MAIL_SEND_STATUS", nullable = false)
	private int sendStatus;

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getFrom() {
		return from;
	}

	public void setFrom(String from) {
		this.from = from;
	}

	public String[] getTo() {
		return to.split(",");
	}

	public void setTo(String... to) {
		this.to = MailUtil.arrayToString(to, ",");
	}

	public String getSender() {
		return sender;
	}

	public void setSender(String sender) {
		this.sender = sender;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public int getSendStatus() {
		return sendStatus;
	}

	public void setSendStatus(int sendStatus) {
		this.sendStatus = sendStatus;
	}

	public String[] getCc() {
		if (cc != null && (!cc.trim().equals(""))) {
			return cc.split(",");
		}
		return null;
	}

	public void setCc(String[] cc) {
		this.cc = MailUtil.arrayToString(cc, ",");
	}

	public String[] getBcc() {
		if (bcc != null && (!cc.trim().equals(""))) {
			return bcc.split(",");
		}
		return null;
	}

	public void setBcc(String[] bcc) {
		this.bcc = MailUtil.arrayToString(bcc, ",");
	}

	@Override
	public String toString() {
		return "MailReply [from=" + from + ", sender=" + sender + ", date=" + date + ", sendStatus=" + sendStatus + "]";
	}

}
